/* Copyright(c) 2010- Siro-info Co.(http://www.siro-info.com)
 * All rights reserved.
 */
package com.siro.pm.ui.view;

import com.siro.pm.model.provider.AdminTreeProvider;
import com.siro.pm.ui.detail.ResetPwdPage;
import com.siro.pm.ui.main.DevelopersPage;
import com.siro.pm.ui.main.ProjectPage;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Tree;

/**
 * Class Declaration:
 * 
 * @version v1.0
 * @since AdminView.java v1.0
 */
public class AdminView extends HorizontalSplitPanel {
	private static final long serialVersionUID = 7368687894401276416L;

	public AdminView() {
	}

	public void createContents() {
		setSizeFull();
		setSplitPosition(20, Sizeable.UNITS_PERCENTAGE);
		// Menu tree, initially shown
		CssLayout menuLayout = new CssLayout();
		menuLayout.addComponent(createMenuTree());
		setFirstComponent(menuLayout);
	}

	private Component createMenuTree() {
		final Tree menuTree = new Tree();
		menuTree.setImmediate(true);
		menuTree.setStyleName("menu");
		menuTree.setContainerDataSource(AdminTreeProvider
				.getAdminTreeContainer());
		menuTree.setItemCaptionPropertyId(AdminTreeProvider.ADMIN_PROPERTY_NAME);
		menuTree.setItemIconPropertyId(AdminTreeProvider.ADMIN_PROPERTY_ICON);
		menuTree.addListener(new ValueChangeListener() {
			private static final long serialVersionUID = 1L;

			public void valueChange(ValueChangeEvent event) {
				Object value = event.getProperty().getValue();
				if (value != null) {
					if (value.equals(AdminTreeProvider.ADMIN_ITEM_DEVELOPER)) {
						DevelopersPage developersPage = new DevelopersPage();
						developersPage.createContents();
						setSecondComponent(developersPage);
					} else if (value
							.equals(AdminTreeProvider.ADMIN_ITEM_PROJECT)) {
						ProjectPage projectPage = new ProjectPage();
						projectPage.createContents();
						setSecondComponent(projectPage);
					} else if (value
							.equals(AdminTreeProvider.ADMIN_ITEM_MODIFYPWD)) {
						ResetPwdPage modifyPwdPage = new ResetPwdPage();
						modifyPwdPage.createContents();
						setSecondComponent(modifyPwdPage);
					}
				}
			}
		});
		return menuTree;
	}

}
